package com.base.action;

import com.common.bean.Rule;
import com.common.util.PagerModel;

public class RuleManagerAction extends RuleAbstractAction {
	private static final long serialVersionUID = -6878644184788417132L;
	
	private Rule rule;
	
	private long ruleno;
	
	private PagerModel pm;

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String getRuleList()  throws Exception {
		int offset = 0;
		int pagesize = 10;
		try{
			offset = Integer.parseInt(getRequest().getParameter("pager.offset"));
		}catch(Exception e){
		}
		
		pm = ruleService.findRulesForPager(offset, pagesize);
		return SUCCESS;
	}
	
	public String addRule() throws Exception {
		ruleService.addRule(rule);
		return SUCCESS;
	}
	
	public String delRule() throws Exception {
		ruleService.removeRule(ruleno);
		return SUCCESS;
	}
	
	public String findRule() throws Exception {
		if(ruleno > 0)
			rule = ruleService.findRule(ruleno);
		return SUCCESS;
	}
	
	public String updateRule() throws Exception {
		ruleService.updateRule(rule);
		return SUCCESS;
	}
	
	/**
	 * @return the pm
	 */
	public PagerModel getPm() {
		return pm;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	/**
	 * @return the rule
	 */
	public Rule getRule() {
		return rule;
	}

	/**
	 * @param rule the rule to set
	 */
	public void setRule(Rule rule) {
		this.rule = rule;
	}

	/**
	 * @return the ruleno
	 */
	public long getRuleno() {
		return ruleno;
	}

	/**
	 * @param ruleno the ruleno to set
	 */
	public void setRuleno(long ruleno) {
		this.ruleno = ruleno;
	}
	
	
}
